<div>

    <div class="content d-flex flex-column flex-column-fluid">
        <sub-header [title]="'ProductSkuEdit' | localize" [description]="sku?.id+' | '+ sku?.title">
            <div action="back"><i class="icon-fanhui text-info" (click)="goBack()"></i></div>
            <div role="actions">
                <a [ngClass]="{'icon-shangyiye':true,'text-primary':sku.preSkuId,'text-secondary':!sku.preSkuId}"
                    (click)="switchSku(false)"></a>
                <a [ngClass]="{'icon-xiayiye':true,'text-primary':sku.nextSkuId,'text-secondary':!sku.nextSkuId}"
                    (click)="switchSku(true)"></a>
            </div>
        </sub-header>

        <div [class]="containerClass">
            <div class="card card-custom gutter-b">
                <div class="card-body">
                    <tabset class="tab-container tabbable-line">
                        <!--  商品sku基础信息-->
                        <tab class="pt-5" heading="{{l('Sku')}}" customClass="kt-tabs__item icon-ccgl-xinghapweihu-4">
                            <form #skuOperationForm='ngForm' name="ProductsForm" (ngSubmit)="save()" novalidate="">
                                <div class="row">
                                    <div class="col-8">
                                        <div class="form-group">
                                            <label>{{l("name")}} *</label>
                                            <input #nameInput="ngModel" class="form-control" type="text" name="title"
                                                [(ngModel)]="sku.title" required maxlength="256">
                                            <validation-messages [formCtrl]="nameInput"></validation-messages>
                                        </div>
                                        <div class="row">
                                            <div class="form-group col-6">
                                                <label>{{l("skuId")}} *</label>
                                                <input #skuIdInput="ngModel" class="form-control" pattern="[0-9a-zA-Z]*"
                                                    type="text" name="skuId" [(ngModel)]="sku.sku_id" required
                                                    maxlength="32">
                                                <validation-messages [formCtrl]="skuIdInput"></validation-messages>
                                            </div>
                                            <div class="form-group col-3">
                                                <label>{{l("PriceArea")}}*</label>
                                                <input #priceInput="ngModel" class="form-control" min="0" maxlength="24"
                                                    pattern="([1-9][0-9]*(\.[0-9]+)?|0)" step="0.01" type="number"
                                                    name="price" [(ngModel)]="sku.price" required>
                                                <validation-messages [formCtrl]="priceInput"></validation-messages>
                                            </div>
                                            <div class="form-group col-3">
                                                <label>&nbsp;</label>
                                                <input #price2Input="ngModel" class="form-control"
                                                    [attr.max]="sku.price" maxlength="24"
                                                    pattern="([1-9][0-9]*(\.[0-9]+)?|0)" step="0.01" type="number"
                                                    name="price2" [(ngModel)]="sku.price2">
                                                <validation-messages [formCtrl]="price2Input"></validation-messages>
                                            </div>
                                        </div>
                                        <div class="row">
                                            <div class="form-group col-6">
                                                <label>{{l("outerId")}}</label>
                                                <input class="form-control" type="text" pattern="[0-9a-zA-Z]*"
                                                    name="outerId" [(ngModel)]="sku.outerId" maxlength="32">
                                            </div>
                                            <div class="form-group col-6">
                                                <label>{{l("auditStatus")}}</label>
                                                <input class="form-control" readonly type="text" name="auditStatus"
                                                    [value]="l(sku.auditStatus||'unknown')">
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="form-group col-6">
                                                <label>{{l("barcode")}}</label>
                                                <input class="form-control" type="text" name="barcode"
                                                    pattern="[0-9a-zA-Z]*" [(ngModel)]="sku.barcode">
                                            </div>
                                            <div class="form-group col-6">
                                                <label>{{l("rfidCode")}}</label>
                                                <input class="form-control" type="text" name="rfidCode"
                                                    pattern="[0-9a-zA-Z]*" [(ngModel)]="sku.rfidCode">
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="form-group col-6">
                                                <label>{{l("promPrice")}}</label>
                                                <input class="form-control" type="text"
                                                    pattern="([1-9][0-9]*(\.[0-9]+)?|0)" name="promPrice"
                                                    [(ngModel)]="sku.promPrice">
                                            </div>
                                            <div class="form-group col-6">
                                                <label>{{l("tags")}}</label>
                                                <p-autoComplete [(ngModel)]="tags" [suggestions]="tagSuggestion"
                                                    (completeMethod)="filter($event)" field="value" dataKey="id"
                                                    [multiple]="true" [dropdown]="true" (onSelect)="assignTags()"
                                                    (onUnselect)="assignTags()" (onBlur)="clearInput($event)"
                                                    placeholder="tags" [minLength]="1" name="MultiSelectInput"
                                                    inputStyleClass="form-control" styleClass="width-percent-100">
                                                </p-autoComplete>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="form-group col-6">
                                                <label>{{l("age")}}</label>
                                                <input class="form-control" type="text"
                                                    pattern="^\b(\d{1,2}(-\d{1,2})?)(\s*,\s*(\d{1,2}(-\d{1,2})?))*\b$"
                                                    name="age" [(ngModel)]="sku.ageScope"
                                                    placeholder="{{l('ageScopePlaceholder')}}">
                                            </div>
                                            <div class="form-group col-6">
                                                <label>{{l("gender")}}</label>
                                                <select type="text" name="gender" class="form-control"
                                                    [(ngModel)]="sku.gender">
                                                    <option value=''>{{l('unknown')}}</option>
                                                    <option value='male'>{{l('male')}}</option>
                                                    <option value='female'>{{l('female')}}</option>
                                                </select>
                                            </div>
                                        </div>

                                        <div class="row">
                                            <div class="col-4">
                                                <div class="form-group">
                                                    <label>{{l("salesVolume")}}</label>
                                                    <input class="form-control" type="text"
                                                        pattern="^(([1-9][0-9]*)|0)\b$" name="salesVolume"
                                                        [(ngModel)]="sku.salesVolume">
                                                </div>
                                            </div>
                                            <div class="col-4">
                                                <div class="form-group">
                                                    <label>{{l("stock")}}</label>
                                                    <input class="form-control" type="number"
                                                        pattern="^(([1-9][0-9]*)|0)\b$" name="quantity"
                                                        [(ngModel)]="sku.quantity">
                                                </div>
                                            </div>
                                            <div class="col-4">
                                                <div class="form-group">
                                                    <label>{{l("orderNumber")}}</label>
                                                    <input class="form-control" type="number"
                                                        pattern="^(([1-9][0-9]*)|0)\b$" step="1" name="orderNumber"
                                                        [(ngModel)]="sku.orderNumber">
                                                </div>
                                            </div>
                                            <div class="col-4">
                                                <div class="form-group">
                                                    <label>{{l("starLevel")}}</label>
                                                    <input class="form-control" type="number" pattern="[1-9][0-9]*"
                                                        name="starLevel" [(ngModel)]="sku.starLevel">
                                                </div>
                                            </div>
                                            <div class="col-4">
                                                <div class="form-group">
                                                    <label>{{l("weight")}}</label>
                                                    <input class="form-control" type="number" name="weight"
                                                        [(ngModel)]="sku.weight">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-4">
                                        <div class="form-group kt-form__group">
                                            <label class="control-label">{{l("Picture")}}</label>
                                            <app-fileupload [fileUrl]="sku.picUrl" (onUpLoadEvent)="onUpload($event)"
                                                (onBeforeSendEvent)="onBeforeSend($event)"></app-fileupload>
                                        </div>
                                    </div>
                                </div>

                                <div class="row">
                                    <div class="col-8" *ngIf="mainProperty.propertyId">
                                        <div class="form-group row">
                                            <label class="col-sm-2 col-form-label"
                                                for="mainPropertyId0">{{mainProperty.propertyName}}*({{l('keyProperty')}}:)</label>
                                            <div class="col-sm-10">
                                                <select [(ngModel)]="mainPropertyIds[0]" name="mainPropertyId0"
                                                    class="form-control" (ngModelChange)="changeImage()">
                                                    <option [value]="value.id"
                                                        *ngFor="let value of mainProperty.propertyValues">
                                                        {{value.value}}
                                                    </option>
                                                </select>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-12" *ngFor="let addProperty of addPropertyList;let i = index;">
                                        <div class="form-group row">
                                            <label [attr.for]="'mainPropertyId'+(i+1)"
                                                class="col-sm-1 col-form-label">{{addProperty.propertyName+':'}}</label>
                                            <div class="col-sm-8">
                                                <select [(ngModel)]="mainPropertyIds[i+1]"
                                                    [name]="'mainPropertyId'+(i+1)" class="form-control">
                                                    <option [value]="value.id"
                                                        *ngFor="let value of addProperty.propertyValues">{{value.value}}
                                                    </option>
                                                </select>
                                            </div>

                                            <!-- 0-{{mainPropertyIds[0]}}//
                                        1-{{mainPropertyIds[1]}}//
                                        2-{{mainPropertyIds[2]}}//
                                        3-{{mainPropertyIds[3]}}//
                                        4-{{addProperty.propertyValues[0].id}} -->
                                            <div class="col-sm-2">
                                                <button type="button" class="btn btn-primary"
                                                    (click)="deleteProperty(i)">{{l('Delete')}}</button>
                                            </div>
                                        </div>
                                    </div>
                                    <div class="col-12" *ngIf="propertyList.length>0">
                                        <div class="form-group row">
                                            <div class="col-8">
                                                <select [(ngModel)]="selectProperty" name="selectProperty"
                                                    class="form-control">
                                                    <option [value]="property.propertyId"
                                                        *ngFor="let property of propertyList">{{property.propertyName}}
                                                    </option>
                                                </select>
                                            </div>

                                            <div class="col-2" *ngIf="selectProperty">
                                                <button type="button" class="btn btn-primary"
                                                    (click)="addProperty()">{{l('add')}}</button>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="form-group col-12">
                                        <label>{{l("description")}}</label>
                                        <textarea class="form-control" name="description"
                                            [(ngModel)]="sku.description"></textarea>
                                    </div>

                                </div>
                                <div class="col-12 text-right">
                                    <button class="btn btn-primary" type="button"
                                        (click)="goBack()">{{l('back')}}</button>
                                    <button class="btn btn-primary" *ngIf="sku.isMine!==false"
                                        [disabled]="!skuOperationForm.form.valid" [buttonBusy]="saving"
                                        [busyText]="l('SavingWithThreeDot')" type="submit">
                                        <i class="fa fa-save"></i>{{l('Save')}}</button>
                                </div>
                            </form>
                        </tab>
                        <!--  电商平台信息-->
                        <tab class="pt-5" heading="{{l('onlineMsg')}}" customClass="kt-tabs__item icon-pingtai1"
                            (selectTab)="getOnlineBySkuId($event)">
                            <div class="row align-items-center">
                                <form class="horizontal-form" autocomplete="off" name="devicesForm">
                                    <div class="kt-form kt-form--label-align-right">
                                        <div class="row align-items-center m--margin-bottom-10">
                                            <div class="offset-4 col-8">
                                                <div class="form-group" style="text-align:right;">
                                                    <div class="input-group" style="display: block;">
                                                        <button type="button" (click)="createOnline()"
                                                            class="btn btn-primary icon-add">{{l('add')}}</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                                <div class="primeng-datatable-container" [busyIf]="onlinePrimeg.isLoading">
                                    <p-table #dataTableOnline (onLazyLoad)="getOnlineBySkuId($event)"
                                        [value]="onlinePrimeg.records" [rows]="onlinePrimeg.defaultRecordsCountPerPage"
                                        [paginator]="false" [lazy]="true"
                                        [resizableColumns]="primengTableHelper.resizableColumns"
                                        [responsive]="primengTableHelper.isResponsive">
                                        <ng-template pTemplate="header">
                                            <tr>
                                                <th style="width:15%">{{l('Actions')}}</th>
                                                <th style="width:5%">{{l('RecordId')}}</th>
                                                <th>{{l('Id')}}</th>
                                                <th>{{l('OnlinePlatform')}}</th>
                                                <th>{{l('price')}}</th>
                                                <th>{{l('num')}}</th>
                                                <th style="width:35%">{{l('QRCodeLink')}}</th>
                                            </tr>
                                        </ng-template>
                                        <ng-template pTemplate="body" let-record let-i="rowIndex">
                                            <tr>
                                                <td>
                                                    <div class="btn-group dropdown" dropdown normalizePosition>
                                                        <button class="dropdown-toggle btn btn btn-primary"
                                                            data-toggle="dropdown" dropdownToggle aria-haspopup="true"
                                                            aria-expanded="false">
                                                            <i class="fa fa-cog"></i>
                                                            <span class="caret"></span> {{l("Actions")}}
                                                        </button>
                                                        <ul class="dropdown-menu" *dropdownMenu>
                                                            <li>
                                                                <a class="icon-bianji dropdown-item"
                                                                    (click)="editOnline(record)">{{l('Edit')}}</a>
                                                            </li>
                                                            <li *ngIf="sku.isMine!==false">
                                                                <a class="icon-icon-test dropdown-item"
                                                                    (click)="deleteOnline(record)">{{l('Delete')}}</a>
                                                            </li>
                                                        </ul>
                                                    </div>
                                                </td>
                                                <td> {{transIndex(i,onlinePrimeg,paginatorOnline)}}</td>
                                                <td>{{record.id}}</td>
                                                <td>
                                                    <span>{{record.onlineStoreName}}</span>
                                                    <!-- <span *ngIf="record.onlineStoreName=='Platform'">平台分类</span> -->
                                                    <!-- <span *ngIf="record.onlineStoreName=='Taobao'">淘宝分类</span> -->
                                                    <!-- <span *ngIf="record.onlineStoreName=='Oracle'">Oracl类</span> -->
                                                    <!-- <span *ngIf="record.onlineStoreName=='JD'">京东</span> -->
                                                    <!-- <span *ngIf="record.onlineStoreName=='BaiSheng'">百盛ERP</span> -->
                                                    <!-- <span *ngIf="record.onlineStoreName=='Shangpai'">商派ER</span>   -->
                                                </td>
                                                <td>{{record.price||EmptyTdText}}</td>
                                                <td>{{record.inventory}}</td>
                                                <td>
                                                    <span>{{record.qrcode}}</span>
                                                </td>
                                            </tr>
                                        </ng-template>
                                        <ng-template pTemplate="emptymessage" let-records>
                                            <tr *ngIf="onlinePrimeg.records">
                                                <td colspan="7">
                                                    <img class="emptymessage"
                                                        src="/assets/common/images/placeholder/onlinestoreHolder.png" />
                                                </td>
                                            </tr>
                                        </ng-template>

                                    </p-table>
                                    <div class="primeng-paging-container">
                                        <p-paginator [rows]="onlinePrimeg.defaultRecordsCountPerPage" #paginatorOnline
                                            (onPageChange)="getOnlineBySkuId($event)"
                                            [totalRecords]="onlinePrimeg.totalRecordsCount"
                                            [rowsPerPageOptions]="onlinePrimeg.predefinedRecordsCountPerPage">
                                        </p-paginator>
                                        <span class="total-records-count">
                                            {{l('TotalRecordsCount', onlinePrimeg.totalRecordsCount)}}
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </tab>
                        <!--  搭配-->
                        <tab class="pt-5" heading="{{l('Match')}}" customClass="kt-tabs__item icon-dapei"
                            (selectTab)="getMatchBySkuId($event)">
                            <div class="row align-items-center">
                                <app-image-grid style="width: 100%;" gridOwner="match"
                                    (onOperate)="onOperateMatch($event)" (onLazyLoad)="getMatchBySkuId($event)"
                                    [imageList]="this.matchPrimeg.records">
                                </app-image-grid>

                                <div class="primeng-datatable-container" [busyIf]="matchPrimeg.isLoading">
                                    <div class="primeng-paging-container">
                                        <p-paginator [rows]="matchPrimeg.defaultRecordsCountPerPage" #paginatorMatch
                                            (onPageChange)="getMatchBySkuId($event)"
                                            [totalRecords]="matchPrimeg.totalRecordsCount"
                                            [rowsPerPageOptions]="matchPrimeg.predefinedRecordsCountPerPage">
                                        </p-paginator>
                                        <span class="total-records-count">
                                            {{l('TotalRecordsCount', matchPrimeg.totalRecordsCount)}}
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </tab>
                        <!--  猜你喜欢-->
                        <tab class="pt-5" heading="{{l('Likes')}}" customClass="kt-tabs__item icon-xin"
                            (selectTab)="getLikesBySkuId($event)">
                            <div class="row align-items-center">
                                <app-image-grid style="width: 100%;" gridOwner="guess"
                                    (onOperate)="onOperateLikes($event)" (onLazyLoad)="getLikesBySkuId($event)"
                                    [imageList]="this.likePrimeg.records">
                                </app-image-grid>

                                <div class="primeng-datatable-container" [busyIf]="likePrimeg.isLoading">
                                    <div class="primeng-paging-container">
                                        <p-paginator [rows]="likePrimeg.defaultRecordsCountPerPage" #paginatorLikes
                                            (onPageChange)="getLikesBySkuId($event)"
                                            [totalRecords]="likePrimeg.totalRecordsCount"
                                            [rowsPerPageOptions]="likePrimeg.predefinedRecordsCountPerPage">
                                        </p-paginator>
                                        <span class="total-records-count">
                                            {{l('TotalRecordsCount', likePrimeg.totalRecordsCount)}}
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </tab>
                        <!--  资源列表-->
                        <tab class="pt-5" heading="{{l('resouceList')}}" customClass="kt-tabs__item icon-ziyuan"
                            (selectTab)="getResBySkuId($event)">
                            <div class="row align-items-center">
                                <form class="horizontal-form" autocomplete="off" name="devicesForm">
                                    <div class="m-form m-form--label-align-right" *ngIf="sku.isMine!==false">
                                        <div class="row align-items-center m--margin-bottom-10">
                                            <div class="offset-4 col-8">
                                                <div class="form-group" style="text-align:right;">
                                                    <div class="input-group" style="display: block;">
                                                        <button type="button" (click)="createResource()"
                                                            class="btn btn-primary icon-add">{{l('add')}}</button>
                                                        <button type="button" (click)="deleteResources()"
                                                            class="btn btn-primary icon-piliangcaozuo">{{l('deleteBatch')}}</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </form>
                                <app-image-grid id="gridShow" style="width: 100%;"
                                    (onOperate)="onOperateResource($event)" (onLazyLoad)="getResBySkuId($event)"
                                    [selection]="resourceSelection" [imageList]="resourcePrimeg.records"
                                    gridOwner="resource"></app-image-grid>
                                <div class="primeng-datatable-container" [busyIf]="resourcePrimeg.isLoading">
                                    <div class="primeng-paging-container">
                                        <p-paginator [rows]="resourcePrimeg.defaultRecordsCountPerPage" #paginatorRes
                                            (onPageChange)="getResBySkuId($event)"
                                            [totalRecords]="resourcePrimeg.totalRecordsCount"
                                            [rowsPerPageOptions]="resourcePrimeg.predefinedRecordsCountPerPage">
                                        </p-paginator>
                                        <span class="total-records-count">
                                            {{l('TotalRecordsCount', resourcePrimeg.totalRecordsCount)}}
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </tab>
                    </tabset>
                </div>
            </div>
        </div>
    </div>
    <createOrEditSkuOnlineModal [editable]="sku.isMine!==false" #createOrEditSkuOnlineModal
        (modalSave)="getOnlineBySkuId()"></createOrEditSkuOnlineModal>
    <createOrEditSkuResourceModal [editable]="sku.isMine!==false" #createOrEditSkuResourceModal
        (modalSave)="getResBySkuId()"></createOrEditSkuResourceModal>